home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual Basic 6.0 Utilities / Multi-Language Add-In for Visual Basic 6.0 / MultiLang.msi / _7CE13D560B6511D5BE510020182C1E5C < prev    next >
Encoding:
Text File  |  2002-01-06  |  3.1 KB  |  97 lines

  1. Attribute VB_Name = "MlStringModule"
  2. Option Explicit
  3.  
  4. 'API declarations
  5. Public Const LOCALE_SLANGUAGE       As Long = &H2  'localized name of Language
  6. Public Const LOCALE_SABBREVLANGNAME As Long = &H3  'abbreviated language name
  7. Public Const LOCALE_SNATIVELANGNAME As Long = &H4  'native name of Language
  8.  
  9. Public Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" _
  10.                         (ByVal Locale As Long, _
  11.                          ByVal LCType As Long, _
  12.                          ByVal lpLCData As String, _
  13.                          ByVal cchData As Long) As Long
  14.  
  15. 'Variables
  16. Public ml_CurrentLanguageId      As Long
  17. Public Const ml_LanguageCount    As Long = 2
  18. Public Const ml_OriginalLanguage As Long = 2057
  19.  
  20. 'Functions
  21. Public Function ml_string(ByVal StringID As Long, Optional ByVal Text As String = "") As String
  22.   ml_string = Text
  23. End Function
  24.  
  25. Public Function ml_LanguageName(ByVal LangIndex As Long) As String
  26.   ml_LanguageName = "Invalid Language Index"
  27. End Function
  28.  
  29. Public Sub ml_ChangeLanguage(ByVal LanguageID As Long, ByVal Language As String)
  30.   
  31.   Dim LanguageIDs As Variant
  32.   Dim Index       As Long
  33.   
  34.   'This function may be called from the ml_RuntimeSupport_LanguageChanged event.
  35.   'This event is used to change the language across separately compiled components
  36.   '(exe, dll, ocx). In this case, the components should support the same languages
  37.   'and use the same IDs. Using non standard language IDs is not recommended.
  38.   
  39.   'The following loop checks that the specified language is supported by this
  40.   'component. If not, then the original language is used.
  41.   
  42.   LanguageIDs = ml_LanguageIds
  43.   ml_CurrentLanguageId = ml_OriginalLanguage
  44.   For Index = LBound(LanguageIDs) To UBound(LanguageIDs)
  45.     If LanguageIDs(Index) = LanguageID Then
  46.       ml_CurrentLanguageId = LanguageID
  47.       Exit For
  48.     End If
  49.   Next
  50.   
  51. End Sub
  52.  
  53. Public Function ml_LanguageIds() As Variant
  54.   ml_LanguageIds = Array(2057, 1031)
  55. End Function
  56.  
  57. 'Helper function for using GetLocaleIndo
  58. Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, _
  59.                                   ByVal dwLCType As Long) As String
  60.  
  61.    Dim sReturn As String
  62.    Dim nSize As Long
  63.  
  64.   'call the function passing the Locale type
  65.   'variable to retrieve the required size of
  66.   'the string buffer needed
  67.    nSize = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
  68.     
  69.   'if successful..
  70.    If nSize Then
  71.     
  72.      'pad a buffer with spaces
  73.       sReturn = Space$(nSize)
  74.        
  75.      'and call again passing the buffer
  76.       nSize = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
  77.      
  78.      'if successful (nSize > 0)
  79.       If nSize Then
  80.       
  81.         'nSize holds the size of the string
  82.         'including the terminating null
  83.          GetUserLocaleInfo = Left$(sReturn, nSize - 1)
  84.       
  85.       End If
  86.    
  87.    End If
  88.     
  89. End Function
  90.  
  91. 'Alternative to ml_LanguageName.
  92. Public Function ml_LocaleName(ByVal LangIndex As Long) As String
  93.   ml_LocaleName = GetUserLocaleInfo(LangIndex, LOCALE_SNATIVELANGNAME)
  94. End Function
  95.  
  96.  
  97.